home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / Prog / S / Simple Sockets 1.0.1.sit / Simple Sockets 1.0.1 ƒ / Sample Apps ƒ / day_server ƒ / source / dayd.c / dayd.c
Encoding:
C/C++ Source or Header  |  1994-09-19  |  1.6 KB  |  104 lines  |  [TEXT/MPCC]

  1. /*
  2.  * dayd.c
  3.  *
  4.  * DayTime server for the Macintosh. Modeled after my Dayd program for UNIX.
  5.  * This program also verifies whether my ip library will work under the printf
  6.  * system.
  7.  *
  8.  */
  9.  
  10. /* Additional Mac Includes */
  11. #include <MacTCPCommonTypes.h>
  12.  
  13. /* Ansi Includes */
  14. #include <stdio.h>
  15. #include <time.h>
  16.  
  17. /* Additional Includes */
  18. #define DAYD
  19. #include "globals.h"
  20. #include "ip.h"
  21.  
  22.  
  23. int daytimed (short sock);
  24. void InitToolBox(void);
  25.  
  26. main()
  27. {
  28.     short msock;
  29.  
  30.     InitToolBox();
  31.     
  32.     //printf("Dyad server for MetroWerks text environment\n");
  33.     if (InitMacTCP() != noErr) {
  34.         SysBeep(3);
  35.         //printf("InitMacTCP() failed!\n");
  36.         return;
  37.     }
  38.  
  39.     msock = socket (IPPROTO_TDP);
  40.     if (msock < 0) {
  41.         //printf("socket() failure!\n");
  42.         return;
  43.     }
  44.     
  45.     if ((bind(msock, 1026) ) < 0) {
  46.     //    printf("bind() failure!\n");
  47.         return;
  48.     }
  49.     
  50.     if ((accept (msock)) < 0) {
  51.         //printf("accept failed: %s\n",gErrno);
  52.         goto foo;
  53.     }
  54.     //printf("msock accepted\n");
  55.     (void) daytimed(msock);
  56.     
  57. foo:
  58.     (void) mac_close (msock);
  59.    // printf("closed stream\n");
  60. }
  61.  
  62.  
  63. void InitToolBox(void)
  64. {
  65.     InitGraf(&qd.thePort);
  66.     InitFonts();
  67.     InitWindows();
  68.     InitMenus();
  69.     TEInit();
  70.     InitDialogs(nil);
  71.     InitCursor();
  72.     
  73. /*    if (InitMacTCP() != noErr) {
  74.         SysBeep(3);
  75.         ExitToShell();
  76.     }*/
  77. }
  78.  
  79. int daytimed(short sock)
  80. {
  81.     time_t tim;
  82.     
  83.     (void) time(&tim);
  84.     (void) mac_write(sock, ctime(&tim), sizeof (time_t));
  85.     return 0;
  86. }    
  87.     
  88.  
  89. /*int daytimed(int sock)
  90. {
  91.     DateTimeRec date;
  92.     char time[40];
  93.     char day[4];
  94.     char month[13];
  95.     
  96.     GetTime(&date);    
  97.     SetDayAndMonth(date, day, month);
  98. }*/
  99.  
  100. /*void SetDayAndMonth(DateTimeRec date, char *day, char *month)
  101. {
  102.     switch (date.month) {
  103.       1:
  104.           strcpy(day, "Jan");*/